App({
  data: {
    servsers: "https://winechun.com/redwhite/index.php?api="
  },
  onLaunch: function () {
    var that = this
    var user = wx.getStorageSync('user') || {};
    var userInfo = wx.getStorageSync('userInfo') || {};
      wx.login({
        success: function (res) {
          console.log(res);
          if (res.code) {
            wx.getUserInfo({
              success: function (user_res) {
                console.log(user_res);
                wx.setStorageSync('userInfo', user_res.userInfo);//存储userInfo  
                wx.request({
                  url: getApp().data.servsers + 'customer/onlogin',
                  data: {
                    code: res.code,
                    nickName:user_res.userInfo.nickName,
                    avatarUrl: user_res.userInfo.avatarUrl,
                  },
                  method: 'POST',   
                  header: {
                    "Content-Type": "application/x-www-form-urlencoded"
                  },
                  success: function (res) {
                    console.log(res.data);
                    var obj = {};
                    obj.openid = res.data.openid;
                    obj.expires_in = Date.now() + res.data.expires_in;
                    console.log(obj);  
                    wx.setStorageSync('user', obj);//存储openid    
                    wx.setStorageSync('session_id', res.data.session_id);//存储openid  
                  }
                });
              }
            });
          } else {
            console.log('获取用户登录态失败！' + res.errMsg)
          }
        }
      });

  },  

  onShow: function () {
    console.log('App Show')
  },
  onHide: function () {
    console.log('App Hide')
  },
  globalData: {
    hasLogin: false
  }
});